package com.hspedu.reflection.class_;

import com.hspedu.Car;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/22
 * @time 18:35
 */
public class GetClass_ {
    public static void main(String[] args) throws ClassNotFoundException {
        //方式一 编译阶段
        String classAllPath = "com.hspedu.Car";
        Class cls = Class.forName(classAllPath);
        System.out.println(cls);

        //方式二，类加载阶段，通过类名获取
        Class cls2 = Car.class;
        System.out.println(cls2);

        //方式3 通过getClass方法获取
        Car car = new Car();
        Class cls3 = car.getClass();
        System.out.println(cls3);

        //方式4 通过类加载器来获取到类的Class对象
        //1. 先得到类加载器
        ClassLoader classLoader = car.getClass().getClassLoader();
        //2. 通过类加载器得到Class对象
        Class cls4 = classLoader.loadClass(classAllPath);

        //方式5
        Class<Integer> integerClass = int.class;
        Class<Byte> byteClass = byte.class;
        Class<Short> shortClass = short.class;
        System.out.println("integerClass = " + integerClass);
        System.out.println("byteClass = " + byteClass);
        System.out.println("shortClass = " + shortClass);

        //方式六
        Class<Integer> type = Integer.TYPE;
        Class<Character> type1 = Character.TYPE;
        Class<Boolean> type2 = Boolean.TYPE;
        System.out.println("type = " + type);
        System.out.println("type1 = " + type1);
        System.out.println("type2 = " + type2);
        System.out.println("type.hashCode() = " + type.hashCode());
        System.out.println("integerClass.hashCode() = " + integerClass.hashCode());

    }
}
